package kassiopeia.plugin.test.assertions;

import kassiopeia.plugin.Event;
import static org.junit.Assert.*;

public class EventBodyAssertion {

    private EventAssertion eventAssertion;
    private Event event;

    public EventBodyAssertion(EventAssertion eventAssertion) {
        this.eventAssertion = eventAssertion;
        this.event = eventAssertion.getEvent();
    }

    public EventAssertion isEmpty() {
        Object body = event.getBody();

        if(body != null) {
            fail("Expected null body, but found: " + body);
        }

        return eventAssertion;
    }

    public EventAssertion isNotEmpty() {
        Object body = event.getBody();

        if(body == null) {
            fail("Expected not null body, but found null");
        }

        return eventAssertion;
    }

    public EventAssertion hasType(Class<?> bodyType) {
        Object body = event.getBody();

        if(body == null) {
            fail("Expected body of type: " + bodyType.getCanonicalName() + " but found: null");
        }

        if(!bodyType.isInstance(body)) {
            fail("Expected body of type: " + bodyType.getCanonicalName() + " but found: " + bodyType.getCanonicalName());
        }

        return eventAssertion;
    }

    public EventAssertion isEqualTo(Object bodyExpected) {
        Object body = event.getBody();

        if(body == null) {
            fail("Expected body: " + bodyExpected + " but found: null");
        }

        if(!bodyExpected.equals(body)) {
            fail("Expected body: " + bodyExpected + " but found: " + body);
        }

        return eventAssertion;
    }
}
